package activiti2;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;


/**
 * 连线（SequenceFlow）
 */
public class LianXian {

    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

    /**部署流程定义+启动流程实例*/
    @Test
    public void deployementAndStartProcess(){
        //部署流程定义
        Deployment deployment = processEngine.getRepositoryService()//获取流程实例
                .createDeployment()//创建部署对象
                .addClasspathResource("diagrams/lianxian.bpmn")
                .deploy();
        System.out.println("部署ID：" + deployment.getId());//部署id
        System.out.println("部署时间：" + deployment.getDeploymentTime());//部署时间

        //启动流程实例
        ProcessInstance pi = processEngine.getRuntimeService()//
                .startProcessInstanceByKey("myProcess_3");//使用流程定义的key的最新版本启动流程
        System.out.println("流程实例ID："+pi.getId());
        System.out.println("流程定义的ID："+pi.getProcessDefinitionId());
    }

    /**完成任务*/
    @Test
    public void completeTask(){
        //任务ID
        String taskId = "65003";
        //完成任务的同时，设置流程变量，让流程变量判断连线该如何执行
        Map<String, Object> variables = new HashMap<String, Object>();
        //其中message对应sequenceFlow.bpmn中的${message=='不重要'}，不重要对应流程变量的值
        variables.put("message", "重要");
        processEngine.getTaskService()//
                .complete(taskId,variables);
        System.out.println("完成任务："+taskId);
    }

}
